package com.sc.nft.entity.vo;

import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.validation.constraints.NotNull;
import java.util.Date;
import java.util.List;

@Data
public class ActivityPropsExchangeDetailVO {

    @ApiModelProperty("id")
    private Long id;

    @ApiModelProperty("道具卡名称")
    private String firstTitle;

    @ApiModelProperty("缩略图")
    private String creationContent;

    @ApiModelProperty("剩余数量")
    private Integer usableCount;

    @ApiModelProperty("是否有参与对象")
    private Boolean isJoin;

    @ApiModelProperty("参与对象名称")
    private String joinName;

    @ApiModelProperty("参与对象图片")
    private String joinImage;

    @ApiModelProperty("是否持有参与对象 true 持有 false 未持有")
    private Boolean isHoldJoin;

    @ApiModelProperty("是否过期 true 不过期 false 过期")
    private Boolean isExpired;

    @ApiModelProperty("过期天数")
    private Integer expiredDay;

    @ApiModelProperty("消耗条件")
    private List<ActivityPropsConfExchangeVO> confList;

    /**
     * 兑换上限
     */
    private Integer upperLimit;

    @ApiModelProperty(value = "剩余可兑换数量")
    private Integer surplusCount;

    @ApiModelProperty(value = "已兑换数量")
    private Integer redeemedQuantity;

    @ApiModelProperty("是否开启注册时间限制")
    @NotNull(message = "是否开启注册时间限制不能为空")
    private Boolean isRegisterTime;

    @ApiModelProperty("注册开始时间")
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    private Date registerBeginTime;

    @ApiModelProperty("注册结束时间")
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    private Date registerEndTime;

    @ApiModelProperty("是否符合注册时间")
    private Boolean isConforRegisterTime=Boolean.FALSE;

    public void setSurplusCount() {
        if (null != upperLimit && null != redeemedQuantity) {
            //计算剩余可兑换数量
            this.surplusCount = Math.max(upperLimit - redeemedQuantity, 0);
            //剩余可兑换数量与总数量比较 计算结果为真实剩余可兑换数量
//            this.surplusCount = Math.min(usableCount, surplusCount);
        }else {
            this.surplusCount=upperLimit;
        }

    }
}
